#include "mock/ArduinoMock.h"
#include "mock/MessageRouterMock.h"
#include "mock/LoggerMock.h"
#include "LightCircuit.h"
using ::testing::Return;
using ::testing::AnyNumber;

TEST(lightCircuit, light){
	ArduinoMock arduino;
	MessageRouterMock r;
	LoggerMock log;

	EXPECT_CALL(arduino, pin(33, arduino.OUT()));
	EXPECT_CALL(arduino, dWrite(33, arduino.HIGHVAL()));
	LightCircuit c(arduino, r, "kitchen", log, 33);

	c.onMessage("{\"dupa\":\"light\", \"id\":\"kitchen\", \"state\":\"on\"}");
	c.onMessage("{\"cmd\":\"dupa\", \"id\":\"kitchen\", \"state\":\"on\"}");
	c.onMessage("{\"cmd\":\"light\", \"dupa\":\"kitchen\", \"state\":\"on\"}");
	c.onMessage("{\"cmd\":\"light\", \"id\":\"dupa\", \"state\":\"on\"}");
	c.onMessage("{\"cmd\":\"light\", \"id\":\"kitchen\", \"dupa\":\"on\"}");

	EXPECT_CALL(arduino, dWrite(33, 0))
		.Times(1);
	c.onMessage("{\"cmd\":\"light\", \"id\":\"kitchen\", \"state\":\"on\"}");
	EXPECT_CALL(arduino, dWrite(33, 1))
		.Times(1);
	c.onMessage("{\"cmd\":\"light\", \"id\":\"kitchen\", \"state\":\"off\"}");
}